<?php
/**
 * Created by PhpStorm.
 * User: alice
 * Date: 2015/12/26
 * Time: 14:14
 */

/**
 * Class Involved_ProjectModel
 */

class Involved_ProjectModel extends BaseModel
{

    protected $table = 'project';

    /**
     * 获取ypt项目列表
     */
    public function YptProjectList($project_id){

           $list = empty($project_id)?
               DB::table($this->table)
                   ->join('company','company.company_name','=','project.company_name')
                   ->where('project.type','1')
                   ->skip(0)->take(3)
                   ->orderBy('project.project_id','desc')
                   ->get():
               DB::table($this->table)
                   ->join('company','company.company_name','=','project.company_name')
                   ->where('project_id',$project_id)
                   ->skip(0)->take(3)
                   ->orderBy('project.project_id','desc')
                   -> get();

        return $list;
    }

    /**
     * 获取sst项目列表
     */
    public function SstProjectList(){

            return DB::table($this->table)
                ->join('company','company.company_name','=','project.company_name')
                ->where('project.type','2')
                ->skip(0)->take(3)
                ->orderBy('project.project_id','desc')
                ->get();

    }

    /**
     * 项目总数
     */
    public function ProjectNum(){
        return  DB::table($this->table)->count();
    }

    /**
     * 项目总规模
     */
    public function ProjectScale(){
        return  DB::table($this->table)
            ->sum('project_scale');
    }


    /**
     * 获取单个项目列表
     * $id项目ID $type项目类别
     */
    public function GetProjectOne($id,$type){
        return  DB::table($this->table)
            ->where(['project_id'=>$id,'type'=>$type])
            ->first();
    }

    /**
     * 账户信息项目推荐
     * @return mixed
     */
    public function UserAccount()
    {
        return DB::table($this->table)
            ->select('project_id','project_name','yield_rate','type','limit','project_scale')
            ->skip(0)->take(4)
            ->get();
    }

    public function YptProjectInfo($project_id)
    {
           $list = empty($project_id)?
               DB::table($this->table)
                   ->join('company','company.company_name','=','project.company_name')
                   ->where('project.type','1')
                   ->orderBy('project.project_id','desc')
                   ->paginate(6):
               DB::table($this->table)
                   ->join('company','company.company_name','=','project.company_name')
                   ->orderBy('project.project_id','desc')
                   ->where('project_id',$project_id)
                   -> paginate(6);

        return $list;

    }


    public function SstProjectInfo()
    {
        return DB::table($this->table)
            ->join('company','company.company_name','=','project.company_name')
            ->where('project.type','2')
            ->paginate(6);
    }




    /**
     * 获取sst
     */
    public function SSTProjectpay($project_id){

        $list = empty($project_id)?
            DB::table($this->table)
                ->join('company','company.company_name','=','project.company_name')
                ->where('project.type','2')
                ->orderBy('project.project_id','desc')
                ->skip(0)->take(3)
                ->get():
            DB::table($this->table)
                ->join('company','company.company_name','=','project.company_name')
                ->where('project_id',$project_id)
                ->orderBy('project.project_id','desc')
                ->skip(0)->take(3)
                -> get();

        return $list;
    }

}